package com.orhon.smartcampus.modules.user.fetcher;

import com.orhon.smartcampus.modules.user.mm.AddressBookMapper;
import com.orhon.smartcampus.modules.user.mutation.AddUserMutation;
import com.orhon.smartcampus.modules.user.mutation.DeleteUserMutation;
import com.orhon.smartcampus.modules.user.mutation.UpdateUserPasswordMutation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import graphql.schema.idl.RuntimeWiring;

@Component
public class UserFetchersLoader {

    @Autowired
    UsersFetcher usersFetcher;

    @Autowired
    AddUserMutation addUserMutation;

    @Autowired
    UserFetcher userFetcher;

    @Autowired
    DeleteUserMutation deleteUserMutation;

    @Autowired
    ByUserNameFetcher byUserNameFetcher;

    @Autowired
    AddressBookFetcher addressBookFetcher;

    @Autowired
    UpdateUserPasswordMutation updateUserPasswordMutation;

    public void LoadFetchers(RuntimeWiring.Builder builder){


        //users -> data
        builder.type("Query" , t->t.dataFetcher("users" , usersFetcher));
        builder.type("Query" , t->t.dataFetcher("user" , userFetcher));
        builder.type("Mutation" , t->t.dataFetcher("addUser" , addUserMutation));
        builder.type("Mutation" , t->t.dataFetcher("deleteUser" , deleteUserMutation));
        builder.type("Mutation" , t->t.dataFetcher("updateUserPassword" , updateUserPasswordMutation));

        //登录用的接口..
        builder.type("Query" , t->t.dataFetcher("userQueryViaName" , byUserNameFetcher));

        //通讯录
        builder.type("Query" , t->t.dataFetcher("addressBooks" , addressBookFetcher));


    }


}
